﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BrandUnion.CustomData;
using Data;

public partial class BookingSite_Competition : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        btnSubmit.Click += new EventHandler(btnSubmit_Click);
    }
    
    void btnSubmit_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            var rep = new BrandUnion.CustomData.BookingCompetitionRepository();

            if (rep.GetBookingByEmailAddress(txtEmail.Text) == null)
            {
                var competition = new BookingCompetition();
                competition.EmailAddress = txtEmail.Text;
                competition.FirstName = txtFirstName.Text;
                competition.LastName = txtSurname.Text;
                competition.MoreInfo = chkAgree.Checked;
                rep.Insert(competition);
                rep.SaveChanges();


                //bla bla bla
                pnlDetails.Visible = false;
                pnlConfirmation.Visible = true;
            }
            else
            {
                pnlErrorMessage.Visible = true;
            }
        }
    }
}
